package com.ewanghuiju.app.presenter.main;

import com.ewanghuiju.app.app.App;
import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.main.WelcomeContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.prefs.ImplPreferencesHelper;
import com.ewanghuiju.app.util.RxUtil;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/11
 */
public class WelcomePresenter extends RxPresenter<WelcomeContract.View> implements WelcomeContract.Presenter {

    private static final String RES = "1080*1776";

    private static final int COUNT_DOWN_TIME = 2000;//2000

    private DataManager mDataManager;

    @Inject
    public WelcomePresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getWelcomeData() {
        ImplPreferencesHelper mImplPreferencesHelper = App.getAppComponent().preferencesHelper();
        boolean isAccepAgreement = mImplPreferencesHelper.getIsAccepAgreement();
        if (isAccepAgreement) {
            //同意了隐私协议
            if (mView != null)
                mView.getPermission();
        } else {
            //未同意  弹出框
//            startCountDown();
            if (mView != null){
                mView.showAccep();
            }
        }
//        if(true){
//            startCountDown();
//            return;
//        }
//        addSubscribe(mDataManager.fetchWelcomeInfo(RES)
//                .compose(RxUtil.<WelcomeBean>rxSchedulerHelper())
//                .subscribe(new Consumer<WelcomeBean>() {
//                    @Override
//                    public void accept(WelcomeBean welcomeBean) {
//                        mView.showContent(welcomeBean);
//                        startCountDown();
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) {
//                        mView.jumpToMain();
//                    }
//                })
//        );
    }

    public void isToGuide() {
        //是否进入引导页
        ImplPreferencesHelper mImplPreferencesHelper = App.getAppComponent().preferencesHelper();
        boolean isFirst = mImplPreferencesHelper.getIsFirst();

    }

    private void startCountDown() {
        addSubscribe(Flowable.timer(COUNT_DOWN_TIME, TimeUnit.MILLISECONDS)
                .compose(RxUtil.<Long>rxSchedulerHelper())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) {
                        if (mView != null){
                            mView.showAccep();
                        }
                    }
                })
        );
    }
}

